﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using Eb;

namespace Ec
{
    public interface BotsPlugin
    {
        //---------------------------------------------------------------------
        void setup(EntityMgr entity_mgr, string ip, int port);
    }

    public static class BotsPluginHelper
    {
        public static BotsPlugin setupBotsPlugin(string dll_file, string class_name, string ip, int port, EntityMgr entity_mgr)
        {
            bool exist_file = File.Exists(dll_file);
            if (!exist_file)
            {
                EbLog.Error("Dll插件文件不存在：" + dll_file);
                return null;
            }

            Assembly ass = Assembly.LoadFrom(dll_file);// 加载dll文件
            Type tp = ass.GetType(class_name);// 获取类名，命名空间+类名
            BotsPlugin bots_plugin = (BotsPlugin)ass.CreateInstance(tp.Name);
            bots_plugin.setup(entity_mgr, ip, port);
            return bots_plugin;
        }
    }
}
